package com.wc.alorithm_luogu._动态规划._树状DP.Barn_Painting_G;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/5/16 9:44
 * @description https://www.luogu.com.cn/problem/P4084
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 200010, idx = 1, P = (int) 1e9 + 7;
    static long[][] f = new long[N][4];
    static int[] h = new int[N], e = new int[N], ne = new int[N];
    static boolean[] st = new boolean[N];
    static int n, m;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        for (int i = 1; i < n; i++) {
            int a = sc.nextInt(), b = sc.nextInt();
            add(a, b);
            add(b, a);
        }
        int root = 1;
        while (st[root]) root++;
        while (m-- > 0) {
            int a = sc.nextInt(), b = sc.nextInt();
            f[a][b] = 1;
            f[a][0] = 1;
        }
        for (int i = 1; i <= n; i++) {
            if (f[i][0] == 0) {
                f[i][1] = f[i][2] = f[i][3] = 1;
            }
        }
        dfs(1, -1);
        long res = (f[1][1] + f[1][2] + f[1][3]) % P;
        out.println(res);
        out.flush();
    }

    static void add(int a, int b) {
        e[idx] = b;
        ne[idx] = h[a];
        h[a] = idx++;
    }

    static void dfs(int u, int fa) {
        for (int i = h[u]; i > 0; i = ne[i]) {
            int j = e[i];
            if (j == fa) continue;
            dfs(j, u);
            f[u][1] = f[u][1] * (f[j][2] + f[j][3]) % P;
            f[u][2] = f[u][2] * (f[j][1] + f[j][3]) % P;
            f[u][3] = f[u][3] * (f[j][1] + f[j][2]) % P;
        }
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
